function readConfigAdm() {
  $.post(baseUrl + "/admin/readconfig/", {}, dialogConfigAdm, "json")
}
function dialogConfigAdm(a) {
  createDialogConfig(a);
  a = $("#dialogAdminIni");
  enterKeyDialogConfig(a);
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_MODIFY] =function() {$(this).dialog("close"); writeConfAdm(); emptyDialogConfig()};
  a.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  a.dialog("open")
}
function enterKeyDialogConfig(a) {
  $(":input", a).keypress(function(b) {
    if(b.which && b.which == 13 || b.keyCode && b.keyCode == 13) {
      a.dialog("close");
      writeConfAdm();
      emptyDialogConfig();
      return false
    }
  })
}
function createDialogConfig(a) {
  $("#server").val(a.server);
  $("#db").val(a.db);
  $("#user").val(a.user);
  $("#pass").val(a.pass);
  $("#graphiz").val(a.graphiz);
  $("#sonde").val(a.sonde);
  $("#tmpPath").val(a.tmpPath);
  return false
}
function emptyDialogConfig() {
  $("#server", "#db", "#user", "#pass", "#graphiz", "#sonde", "#tmpPath").val("");
  return false
}
function writeConfAdm() {
  $.post(baseUrl + "/admin/writeconfig/", {server:$("#server").val(), db:$("#db").val(), user:$("#user").val(), pass:$("#pass").val(), graphiz:$("#graphiz").val(), sonde:$("#sonde").val(), tmpPath:$("#tmpPath").val()}, alertGrowl(ADMIN_CONFIG1, ADMIN_CONFIG2), "json")
}
function dialogCache() {
  getSizeCache();
  var a = $("#dialogAdminCache");
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_EMPTY_SESSION] =function() {$(this).dialog("close"); emptyCacheSession()};
  btns[BUTTON_EMPTY_ALL] =function() {$(this).dialog("close"); emptyCacheAll()};
  a.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  a.dialog("open")
}
function getSizeCache() {
  $.post(baseUrl + "/admin/sizecache/", {}, putSizeCache, "json")
}
function emptyCacheAll() {
  $.post(baseUrl + "/admin/emptycache/", {}, alertGrowl(ADMIN_CACHE, ADMIN_CACHE_EMPTY), "json")
}
function emptyCacheSession() {
  $.post(baseUrl + "/admin/emptycachesession/", {}, alertGrowl(ADMIN_CACHE, ADMIN_CACHE_EMPTY), "json")
}
function putSizeCache(b) {
  var a = $("#sizeCacheAdmin");
  a.empty();
  a.append( ADMIN_CACHE_SIZE_ALL + " : " + b.sizeAll + "<br/>");
  a.append( ADMIN_CACHE_SIZE_SESSION + " : " + b.sizeSession);
  return false
}
function dialogVersion() {
  getVersion();
  var a = $("#dialogAdminVersion");
  var btns = {};
  btns[BUTTON_OK] = function() {$(this).dialog("close")};
  a.dialog({autoOpen:false, draggable:true, width:"150px", modal:true, buttons:btns});
  a.dialog("open")
}
function getVersion() {
  $.get(baseUrl + '/admin/getversion', {}, getVersionResp, "json")
}
function getVersionResp(a) {
    var b = $("#versionAdmin");
    b.empty();
    b.append(a.version);
}